/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.googlecode.jmicroerp.wicket.administrare;

import com.googlecode.jmicroerp.model.Produs;
import com.googlecode.jmicroerp.model.Recipient;
import com.googlecode.jmicroerp.service.GenericService;
import com.googlecode.jmicroerp.wicket.DefaultViewPage;
import com.googlecode.jmicroerp.wicket.components.grid.ActionButton;
import com.googlecode.jmicroerp.wicket.components.grid.ActionButtons;
import com.googlecode.jmicroerp.wicket.components.grid.ColumnModel;
import com.googlecode.jmicroerp.wicket.components.grid.DefaultGridAction;
import com.googlecode.jmicroerp.wicket.components.grid.Grid;
import com.googlecode.jmicroerp.wicket.components.grid.PageParameters;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import org.apache.wicket.spring.injection.annot.SpringBean;

/**
 *
 * @author Alexandru.Codescu
 */
public class VizualizareRecipientePage extends DefaultViewPage {
    @SpringBean(name = "defaultGridAction")
    private DefaultGridAction<Recipient> gridAction;
    @SpringBean(name = "genericService")
    private GenericService<Recipient> genericService;
    
    public VizualizareRecipientePage() {
        ColumnModel[] grids = {
            new ColumnModel("Denumire", "denumire", String.class),
            new ColumnModel("Magazin", "magazin.denumire", String.class),
            new ColumnModel("Tip recipient", "tipRecipient.denumire", String.class),
            new ColumnModel("Ordine", "ordine", BigDecimal.class),
            new ColumnModel("Activ", "activ", Boolean.class)
        };
        List<ColumnModel> columns = Arrays.asList(grids);
        ActionButton actionButton = new ActionButton(new PageParameters(EditareRecipientePage.class));
        ActionButton deleteButton = new ActionButton("stergere", new PageParameters()) {

            @Override
            public void doAction(Long id) {
                Recipient recipient = genericService.getById(Recipient.class, id);
                recipient.setActiv(Boolean.FALSE);
                genericService.update(recipient);
                setResponsePage(VizualizareRecipientePage.class);
            }
            
        };        
        
        ActionButtons actionButtons = new ActionButtons(actionButton, deleteButton);
        Grid<Recipient> dataGridConsum = new Grid<Recipient>("grid", columns, Recipient.class, gridAction, actionButtons);
        add(dataGridConsum);
    }
    
}
